/*
 * @Author: wang.xiao 
 * @Date: 2017-10-21 09:31:03
 * QQ技术交流群: 329065035
*/

class GameStartPanel extends egret.Sprite{
	
	// 事件类型
	public static GAME_START: string = "gameStart";
	// 背景
	private bg: egret.Bitmap;
	// 按钮
	private startBtn: MBtn;

	public constructor() {
		super();
		// 初始化页面
		this.init();
	}
	private init() {
		// 实例化背景
		this.bg = new egret.Bitmap(RES.getRes("gameStartBg_png"));
		// 添加到显示列表
		this.addChild(this.bg);
		this.bg.width = Data.getStageW();
		this.bg.height = Data.getStageH();
		
		this.startBtn  = new MBtn("primary",100,100,120,40);
		this.addChild(this.startBtn); 
		this.startBtn.btnText.text = "22222";
		this.startBtn.btnText.size = 16;
		
		this.startBtn.x = (Data.getStageW() - this.startBtn.width) * 0.5;
		this.startBtn.y = Data.getStageH() * 0.5 + 50;
	}
	// 开始监听的配置
	public start(){
		// 开启点击属性
		this.startBtn.touchEnabled = true;
		this.startBtn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onTouchTap,this);
	}
	private onTouchTap(e: egret.TouchEvent){
		
		// 注册自定义事件
		var changeEvent = new ChangeSceneEvent(ChangeSceneEvent.CHANGE_SCENE_EVENT);
		changeEvent.eventType = GamePlayingPanel.CHANGEPANEL;
		changeEvent.obj = this;
		// 触发事件
		SceneManager.getInstance().dispatchEvent(changeEvent);
	}
	// 释放资源
	public end(){
		this.startBtn.touchEnabled = false;
		if(this.startBtn.hasEventListener(egret.TouchEvent.TOUCH_TAP)){
			this.startBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.onTouchTap,this);
		}
	}
}